package com.metadata_system.system.response;


import com.fasterxml.jackson.annotation.JsonFormat;
import com.metadata_system.common.db.entity.MetadataNode;
import com.metadata_system.common.db.entity.Project;
import com.metadata_system.common.db.entity.ProjectNode;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.Date;
import java.util.List;
import java.util.Map;

@AllArgsConstructor
@NoArgsConstructor
@Builder
@Data
public class ProjectDetailResponse {
    private Integer id;
    private Integer databaseId;
    private String databaseName;
    private Integer metadataId;
    private String metadataName;
    private String name;
    private String shortName;
    private String description;

    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    private Date createdTime;
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    private Date updatedTime;


    private String username;
    private Integer nodeTotal;
    private Integer dataTotal;
    private Object user;
    private Object userList;
    private List<ProjectNodeResponse> projectNodeList;
    private List<NodeItem> metadataNodeList;
    private List<Map<String,Object>> unReadProjectLogMap;
    private List<String> ownRoles;

    public static ProjectDetailResponse fromEntity(Project project, List<ProjectNode> metadataNodeList) {
        return ProjectDetailResponse.builder()
                .id(project.getId())
                .name(project.getName())
                .shortName(project.getShortName())
                .description(project.getDescription())
                .createdTime(project.getCreatedTime())
                .updatedTime(project.getUpdatedTime())
                .nodeTotal(metadataNodeList.size())
                .dataTotal(project.getDataTotal())
                .projectNodeList(ProjectNodeResponse.fromEntityList(metadataNodeList))
                .build();
    }
}
